﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OneSoft.DataAccess;
using OneSoft.EntityCore;
using System.Data;

using BySoft.Server.Common.Entity;
using BySoft.Server.Common.Schema;
using BySoft.Server.Consts;
using BySoft.Server.Common.Enum;
using System.Data.OleDb;
using BySoft.Server.Common;

namespace BySoft.Server.DataAccess
{
    public partial class ClsQueryDA
    {
        public static DataTable QueryProjectCostDynamicList(string MasterPerson, string strtxtProjectID, string strtxtProjectName, string strddlConstructionStatus, string strtxtContractorInfoName, string strtxtMasterPersonName, string ProjectType, string CheckAmount, string ContractAgreementAmount)
        {
            DataAccessParameterCollection dpc = new DataAccessParameterCollection();
            string strcmd = @"SELECT * FROM V_ProjectCostDynamic a WHERE 1=1";

            if (!string.IsNullOrEmpty(strtxtProjectID))
            {
                strcmd += " AND a.ProjectID LIKE @ProjectID";
                dpc.AddWithValue("@ProjectID", "%" + strtxtProjectID + "%");
            }
            if (!string.IsNullOrEmpty(strtxtProjectName))
            {
                strcmd += " AND a.ProjectName LIKE @ProjectName";
                dpc.AddWithValue("@ProjectName", "%" + strtxtProjectName + "%");
            }
            if (!string.IsNullOrEmpty(strddlConstructionStatus))
            {
                strcmd += " AND a.ConstructionStatus = @ConstructionStatus";
                dpc.AddWithValue("@ConstructionStatus", strddlConstructionStatus);
            }
            if (!string.IsNullOrEmpty(strtxtContractorInfoName))
            {
                strcmd += " AND a.ContractorInfoName LIKE @ContractorInfoName";
                dpc.AddWithValue("@ContractorInfoName", "%" + strtxtContractorInfoName + "%");
            }
            if (!string.IsNullOrEmpty(strtxtMasterPersonName))
            {
                strcmd += " AND a.MasterPersonName LIKE @MasterPersonName";
                dpc.AddWithValue("@MasterPersonName", "%" + strtxtMasterPersonName + "%");
            }
            if (!string.IsNullOrEmpty(ProjectType))
            {
                strcmd += " AND a.ProjectType = @ProjectType";
                dpc.AddWithValue("@ProjectType", ProjectType);
            }
            if (!string.IsNullOrEmpty(CheckAmount))
            {
                strcmd += " AND a.CheckAmount IS NULL";
            }
            if (!string.IsNullOrEmpty(ContractAgreementAmount))
            {
                strcmd += " AND a.ContractAgreementAmount IS NULL";
            }
            if (!string.IsNullOrEmpty(MasterPerson))
            {
                strcmd += " AND a.MasterPerson = @MasterPerson";
                dpc.AddWithValue("@MasterPerson", MasterPerson);
            }

            strcmd += " ORDER BY a.ProjectID DESC";
            try
            {
                return ClsCommDA.ExeDataTable(strcmd, dpc);
            }
            catch
            {
                throw;
            }
        }



        public static decimal SelectSystemParam(string strSystemParamID)
        {
            DataAccessParameterCollection dpc = new DataAccessParameterCollection();
            string strcmd = @"SELECT a.SystemParamName FROM BS_SystemParam a WHERE a.SystemParamID=@SystemParamID";
            dpc.AddWithValue("@SystemParamID", strSystemParamID);
            string str = ClsCommDA.ExeString(strcmd, dpc);
            return CommonMethod.ConvertToDecimal(str);
        }
    }
}
